package com.zyb.warehouse.controller;

import com.zyb.warehouse.common.Result;
import com.zyb.warehouse.entity.ProductType;
import com.zyb.warehouse.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description:商品分类控制层
 */
@RestController
@RequestMapping("/productCategory")
public class ProductTypeController {

    @Autowired
    private ProductTypeService productTypeService;

    /**
     * 查询所有商品分类
     *
     * @return
     */
    @GetMapping("/product-category-tree")
    public Result queryAllProductCategory() {
        List<ProductType> typeList = productTypeService.queryCategoryTree();
        return Result.ok(typeList);
    }

    /**
     * 验证商品分类编号是否重复
     *
     * @param typeCode
     * @return
     */
    @GetMapping("/verify-type-code")
    public Result verifyTypeCode(String typeCode) {
        Result result = productTypeService.verifyTypeCode(typeCode);
        return result;
    }

    /**
     * 添加商品分类
     *
     * @param productType
     * @return
     */
    @PostMapping("/type-add")
    public Result addProductCategory(@RequestBody ProductType productType) {
        Result result = productTypeService.addProductCategory(productType);
        return result;
    }

    /**
     * 删除商品分类
     *
     * @param typeId
     * @return
     */
    @DeleteMapping("/type-delete/{typeId}")
    public Result removeProductCategory(@PathVariable("typeId") Integer typeId) {
        Result result = productTypeService.removeProductCategory(typeId);
        return result;
    }

    /**
     * 修改商品分类
     *
     * @param productType
     * @return
     */
    @PutMapping("/type-update")
    public Result modifyProductCategory(@RequestBody ProductType productType) {
        Result result = productTypeService.modifyProductCategory(productType);
        return result;
    }
}
